##################################################################################################################################
#
# Copyright (C) 2008-2013 Mind System Connection. Lda. Part of Daidze Software, created by Siqsuruq. All other rights reserved.
#
# Mind System Connection Webpage: www.msysc.org
# Daidze Software Page: www.daidze.com www.daidze.org
# E-mail: admin@msysc.org, siqsuruq@gmail.com
#
##################################################################################################################################

proc check_imagemagic {} {
	if {$::image_magic ne ""} {
	
	} else {
		tk_messageBox -icon error -type ok -message "[::msgcat::mc "You need to define path to ImageMagick utility."]"
	}
}

proc set_img {img_label} {
	set ::types {{"Image Files" {.jpeg .jpg .png}} {"Image Files" "" {JPEG}}}
	set a [tk_getOpenFile -filetypes $::types -title "[::msgcat::mc "Image Files"]"]

	if {$a ne ""} {
		set img_convert [file join $::image_magic convert]
		
		set temp_img [::fileutil::tempfile]
		exec $img_convert -resize 250 $a $temp_img

		set file_type [lindex [::fileutil::magic::mimetype $temp_img] 0]
		
		if {$file_type eq "image/x-gif"} {
			set ext gif
		} elseif {$file_type eq "image/x-png"} {
			set ext png
		} elseif {$file_type eq "image/jpeg"} {
			set ext jpeg
		}
				
		set pic [image create photo -file $temp_img -format $ext]
		$img_label configure -image $pic
	}
}

proc image_viewer {img} {
	set img_view [top_win "Image viewer"]
	pack [ttk::label $img_view.l -image $img]
	
}


proc img_viewer {img} {
	set viewer .viewer
	catch {destroy $viewer}
	toplevel $viewer
	wm title $viewer [::msgcat::mc "Image viewer"]
	image create photo img_data -file $img
	
	pack [ttk::label $viewer.picture -image img_data]
}